package com.wolfsea.viewpagerrecyclerviewpageing.pagemenulibrary.holder
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.wolfsea.viewpagerrecyclerviewpageing.R
import com.wolfsea.viewpagerrecyclerviewpageing.model.ModelHomeEntrance
import com.wolfsea.viewpagerrecyclerviewpageing.utils.ScreenUtil

/**
 *@desc RV ViewHolder
 *@author liuliheng
 *@time 2022/3/4  0:12
 **/
class HomeEntranceViewHolder(itemView: View) : AbstractHolder<ModelHomeEntrance>(itemView) {

    private lateinit var imageView: ImageView
    private lateinit var textView: TextView

    override fun initView(itemView: View?) {
        itemView?.let {
            val width = RecyclerView.LayoutParams.MATCH_PARENT
            val height = ScreenUtil.dip2px(it.context.resources.getDimension(R.dimen.dp_40))
            val layoutParam = RecyclerView.LayoutParams(width, height)
            it.layoutParams = layoutParam
            imageView = it.findViewById(R.id.entrance_image)
            textView = it.findViewById(R.id.entrance_name)
        }
    }

    override fun bindView(holder: RecyclerView.ViewHolder?, data: ModelHomeEntrance?, pos: Int) {
        data?.apply {
            imageView.setImageResource(image)
            textView.text = "${name}:${pos}"
        }
    }

}